//
// Created by benxb on 2021/12/21.
//

#include <index/linear_index_segment_reader.h>

namespace benxdb {


LinearIndexSegmentReader::LinearIndexSegmentReader(const std::shared_ptr<LinearIndexSegment>& segment)
 : segment_(segment), page_index_(0), record_index_(0) {
    segment->GetIndexPage(page_index_, page_);
}

bool LinearIndexSegmentReader::HasMoreIndex() {
    if (record_index_ < page_.GetIndexSize()) {
        return true;
    }
    page_index_++;
    if (segment_->GetIndexPage(page_index_, page_)) {
        record_index_ = 0;
        return true;
    } else {
        return false;
    }
}

LinearIndexLeafPair LinearIndexSegmentReader::GetNextIndexPair() {
    auto res_pair = page_.GetIndexPair(record_index_);
    record_index_++;
    return res_pair;
}

LinearIndexSegmentReader::~LinearIndexSegmentReader() = default;


}
